<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index extends  Controller
{
    public function index()
    {
        return '555';
       /* $c=Db::connect()->name('goods')->find();
        *$b=db('goods')->select();
        * db('goods') 等同于 Db::connect()->name('goods') 等同于 Db::name('goods');
        */
        $str = 'Hello I am a very very very very long string';
        $compressed = gzcompress($str, 1);//压缩级别为9
        p($compressed); 
        $uncompressed = gzuncompress($compressed);
        p($uncompressed);die;

        $ar=Db::table('my_goods')->select();

        $this->error();
        p($ar);
        $this->view->age=28;
        $this->assign('name','赵大伟');

       return  $this->fetch('index');
    }

    public function _empty(){


        return $this->fetch('public/404');
    }

    public function upload(){
        if($_POST){
            // 获取表单上传文件 例如上传了001.jpg
            $file = request()->file('image');
            // 移动到框架应用根目录/public/uploads/ 目录下
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($info){
                // 成功上传后 获取上传信息
                // 输出 jpg
                echo $info->getExtension();
                // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
                echo $info->getSaveName();
                // 输出 42a79759f284b767dfcb2a0197904287.jpg
                echo $info->getFilename();
            }else{
                // 上传失败获取错误信息
                echo $file->getError();
            }
        }

        return $this->fetch();
    }
}
